<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>回文检查器</title>
    </head>
    <body>
        <script src="./js/deque.js"></script>
        <script>
            function palidromeChecker(aString) {
                if (
                    aString === undefined ||
                    aString === null ||
                    (aString !== null && aString.length === 0)
                ) {
                    return false;
                }
                const deque = new Deque();
                // 这一步是去掉中间的空格
                const lowerString = aString
                    .toLocaleLowerCase()
                    .split(" ")
                    .join(""); //
                console.log(lowerString);
                let isEqual = true;
                let firstChar, lastChar;
                // 首先我们创建一个双端数组，并且将字母存进去
                for (let i = 0; i < lowerString.length; i++) {
                    deque.addBack(lowerString.charAt(i));
                }

                while (deque.size() > 1 && isEqual) {
                    firstChar = deque.removeFront();
                    lastChar = deque.removeBack();
                    if (firstChar !== lastChar) {
                        isEqual = false;
                    }
                }

                return isEqual;
            }
            console.log("javascript", palidromeChecker("javascript"));
            console.log("level", palidromeChecker("level"));
            console.log("Step on no pets", palidromeChecker("Step on no pets"));
        </script>
    </body>
</html>
